
const configure = {
    state: {    //存储的字段
        HOST: 'http://127.0.0.1:8888',  //后台访问地址根目录
        activeName: '',  //当前选中的菜单名
        showAside: false,   //是否显示播放中的歌曲列表
        loginIn: false,     //用户是否已登录
        isSongActive: false,//当前歌曲是否已收藏
    },
    getters: {  //getter方法
        activeName: state => {
            let activeName = state.activeName;
            if(!activeName){
                //如果没有，从window中获取
                activeName = JSON.parse(window.sessionStorage.getItem("activeName"));
            }
            return activeName;
        },
        showAside: state => {
            let showAside = state.showAside;
            if(!showAside){
                //如果没有，从window中获取
                showAside = JSON.parse(window.sessionStorage.getItem("showAside"));
            }
            return showAside;
        },
        loginIn: state => {
            let loginIn = state.loginIn;
            if(!loginIn){
                //如果没有，从window中获取
                loginIn = JSON.parse(window.sessionStorage.getItem("loginIn"));
            }
            return loginIn;
        },
        isSongActive: state => {
            let isSongActive = state.isSongActive;
            if(!isSongActive){
                //如果没有，从window中获取
                isSongActive = JSON.parse(window.sessionStorage.getItem("isSongActive"));
            }
            return isSongActive;
        }
    },
    mutations: {    //setter方法
        setActiveName:(state, activeName) => {
            state.activeName = activeName;
            window.sessionStorage.setItem("activeName", JSON.stringify(activeName));
        },
        setShowAside:(state, showAside) => {
            state.showAside = showAside;
            window.sessionStorage.setItem("activeName", JSON.stringify(showAside));
        },
        setLoginIn:(state, loginIn) => {
            state.loginIn = loginIn;
            window.sessionStorage.setItem("loginIn", JSON.stringify(loginIn));
        },
        setIsSongActive:(state, isSongActive) => {
            state.isSongActive = isSongActive;
            window.sessionStorage.setItem("isSongActive", JSON.stringify(isSongActive));
        }
    }
};
export default configure;